/**
 * 
 */
package com.wodsy.phoenix.dataservice.cms.service.impl;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.dubbo.container.Main;
import com.wodsy.phoenix.datadao.base.IBaseDao;
import com.wodsy.phoenix.datadao.cms.dao.CmsHomePageNewGoodsDao;
import com.wodsy.phoenix.dataobject.base.Pager;
import com.wodsy.phoenix.dataobject.cms.constants.HomePageObjectType;
import com.wodsy.phoenix.dataobject.cms.model.IdxNewGoodsRecommended;
import com.wodsy.phoenix.dataobject.cms.vo.IdxNewGoodsRecResp;
import com.wodsy.phoenix.dataservice.base.AbstractBaseService;
import com.wodsy.phoenix.dataservice.cms.aop.AfterOperation;
import com.wodsy.phoenix.dataservice.cms.service.CmsHomePageNewGoodsService;

/**
 * @author bryan
 *
 */
@Service(interfaceClass = CmsHomePageNewGoodsService.class, interfaceName = "com.wodsy.phoenix.dataservice.cms.service.CmsHomePageNewGoodsService")
public class CmsHomePageNewGoodsServiceImpl extends AbstractBaseService<IdxNewGoodsRecommended,Integer> implements
		CmsHomePageNewGoodsService {
	@Autowired
	CmsHomePageNewGoodsDao cmsHomePageNewGoodsDao;
	
	@Override
	protected IBaseDao<IdxNewGoodsRecommended, Integer> getIBaseDao() {
		return cmsHomePageNewGoodsDao;
	}
	
	@Transactional(readOnly=true)
	@Override
	public List<IdxNewGoodsRecResp> getOnlineNewGoodsRec() {
		List<IdxNewGoodsRecommended> list = cmsHomePageNewGoodsDao.getOnlineNewGoodsRec();
		List<IdxNewGoodsRecResp> respList = new ArrayList<IdxNewGoodsRecResp>();
		IdxNewGoodsRecResp resp = null;
		for (IdxNewGoodsRecommended newGoods : list) {
			resp = new IdxNewGoodsRecResp();
			try {
				BeanUtils.copyProperties(resp, newGoods);
				respList.add(resp);
			} catch (IllegalAccessException | InvocationTargetException e) {
				logger.error("object copy error!", e);
			}
		}
		return respList;
	}

	@Transactional(readOnly=true)
	@Override
	public Pager<IdxNewGoodsRecommended> searchNewGoodsRecByOrder(
			Pager<IdxNewGoodsRecommended> newGoodsRec,
			IdxNewGoodsRecommended goodsreq) {
		Pager<IdxNewGoodsRecommended> pager = cmsHomePageNewGoodsDao.searchNewGoodsRecByOrder(newGoodsRec,goodsreq);
		return pager;
	}

	@Transactional(readOnly=false)
	@Override
	public Integer updateGoodsRecommendedStatus(int goods_recId, int status) {
		return cmsHomePageNewGoodsDao.updateGoodsRecommendedStatus(goods_recId, status);
	}
	
	@Transactional(readOnly=false)
	@Override
	public Integer updateGoodsRecommendedStatus(Integer[] goods_recIds, int status) {
		return cmsHomePageNewGoodsDao.updateGoodsRecommendedStatus(goods_recIds, status);
	}
	
	@Transactional(readOnly=false)
	@AfterOperation(objectId="#newGoods.id",objectType=HomePageObjectType.NEWGOODSRECOMMENDED,
	offlineTime="#newGoods.offlineTime",onlineTime="#newGoods.onlineTime" )
	@Override
	public Integer addNewGoodsRecommended(IdxNewGoodsRecommended newGoods) {
		Integer newId = cmsHomePageNewGoodsDao.addNewGoodsRecommended(newGoods);
		
		return newId;

	}
	
	@Transactional(readOnly=false)
	@AfterOperation(objectId="#newGoods.id",objectType=HomePageObjectType.NEWGOODSRECOMMENDED,
	offlineTime="#newGoods.offlineTime",onlineTime="#newGoods.onlineTime" )
	@Override
	public void updateNewGoodsRecommended(IdxNewGoodsRecommended newGoods) {
		cmsHomePageNewGoodsDao.updateNewGoodsRecommended(newGoods);
	}
	public static void main(String[] args) {
		Main.main(args);
	}
}
